﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ProgramMain.Database;

namespace ProgramMain.OpticNet
{
    public partial class CableDetail : ProgramMain.Framework.BaseModalDetailCtl
    {
        public CableDetail()
        {
            InitializeComponent();
        }
        protected override void InitializeDataControls()
        {
            this.curveElementTypesTableAdapter.SelectCommandTimeout =
                ProgramMain.Properties.Settings.Default.LongQueryTimeout;
            this.curveElementTypesTableAdapter.Fill(this.simpleOpticNetDB.CurveElementTypes, 1);

            if (ShowMode == ShowModeTypes.Add)
            {
                SimpleOpticNetDB.CableRow row = (SimpleOpticNetDB.CableRow) (CurrentRowView).Row;
                if (this.curveElementType.Count > 0)
                {
                    this.curveElementType.MoveFirst();
                    SimpleOpticNetDB.CurveElementTypesRow vertexTypesRow =
                        (SimpleOpticNetDB.CurveElementTypesRow) ((DataRowView) this.curveElementType.Current).Row;
                    if(row != null && vertexTypesRow != null)
                    row.CurveElementTypeID = vertexTypesRow.ID;
                }
            }
        }

        protected override void BindDataControls()
        {
            lookCableType.DataBindings.Add(new Binding("EditValue", this.dataSource, "CurveElementTypeID"));
            memoCableComment.DataBindings.Add(new Binding("Text", this.dataSource, "Description"));
            txtCableName.DataBindings.Add(new Binding("Text", this.dataSource, "Caption"));
            txtCableLength.DataBindings.Add(new Binding("Text", this.dataSource, "CableLength"));
            lookCableType.Enabled = ShowMode == ShowModeTypes.Add;
        }
    }
}
